
using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;

namespace Microsoft.NETMF.BikeComputer.Application
{
    public class ZeroInclinometerView : View
    {

        public ZeroInclinometerView(RideDataModel model, ComputerController controller)
            : base(model)
            
        {
            _controller = controller;

            _zeroPanel = new StackPanel(Orientation.Vertical);  
            _zeroPanel.HorizontalAlignment = HorizontalAlignment.Center;
            _zeroPanel.VerticalAlignment = VerticalAlignment.Center;

            ////////////////////////////////////////////////////////////////////////////////////////
            //  title area
            //

            StackPanel titlePanel = new StackPanel(Orientation.Vertical);
            titlePanel.HorizontalAlignment = HorizontalAlignment.Center;
            titlePanel.VerticalAlignment = VerticalAlignment.Top;
            titlePanel.SetMargin(10, 0, 10, 0);

            Text titleText = new Text (Resources.GetFont(Resources.FontResources.nina48),Resources.GetString(Resources.StringResources.ZeroTitle));
            titleText.HorizontalAlignment = HorizontalAlignment.Center;
            titleText.VerticalAlignment = VerticalAlignment.Top;

            Text subTitleText = new Text(Resources.GetFont(Resources.FontResources.miramob), Resources.GetString(Resources.StringResources.ZeroSubTitle));

            titlePanel.Children.Add(titleText);
            titlePanel.Children.Add(subTitleText);

            ////////////////////////////////////////////////////////////////////////////////////////
            //  button area
            //
            
            StackPanel buttonPanel = new StackPanel(Orientation.Vertical);
            buttonPanel.HorizontalAlignment = SPOT.Presentation.HorizontalAlignment.Center;

            buttonPanel.SetMargin(40, 10, 10, 15);

            _startZeroing = new UIButton(Resources.GetString(Resources.StringResources.StartButtonText), Resources.GetFont(Resources.FontResources.miramob));
            _startZeroing.Click += new EventHandler(_start_Click);
                
 
            buttonPanel.Children.Add(_startZeroing);
            
            /////////////////////////////////////////////////////////////////////////////////////////////////
            //  Date area
            //
            StackPanel datePanel = new StackPanel(Orientation.Vertical);
            datePanel.HorizontalAlignment = HorizontalAlignment.Center;
            datePanel.VerticalAlignment = VerticalAlignment.Bottom;

            Text dateTime = new Text(Resources.GetFont(Resources.FontResources.miramob), model.getToday().ToString());

            datePanel.Children.Add(dateTime);

            /////////////////////////////////////////////////////////////////////////////////////////////////
            //  processing area
            //
            _processingPanel = new StackPanel(Orientation.Vertical);
            _processingPanel.Visibility = Visibility.Hidden;
            datePanel.HorizontalAlignment = HorizontalAlignment.Center;
            datePanel.VerticalAlignment = VerticalAlignment.Bottom;

            Text processing = new Text(Resources.GetFont(Resources.FontResources.miramob), Resources.GetString(Resources.StringResources.ZeroingText));

            _processingPanel.Children.Add(processing);


            ///////////////////////////////////////////////////////////////////////////////////////
            //  panel Setup
            //

            _zeroPanel.Children.Add(titlePanel);
            _zeroPanel.Children.Add(buttonPanel);
            _zeroPanel.Children.Add(datePanel);
            _zeroPanel.Children.Add(_processingPanel);

            Child = _zeroPanel;

        }

        private void _start_Click (object e, EventArgs args)
        {
            _processingPanel.Visibility = SPOT.Presentation.Visibility.Visible;
            this.Invalidate();
            _controller._inclineSensor.ZeroInclinometer();
            _processingPanel.Visibility = SPOT.Presentation.Visibility.Hidden;
            this.Invalidate();
        }


        private UIButton _startZeroing;
        private ComputerController _controller;
        private StackPanel _zeroPanel;
        private StackPanel _processingPanel;


    }
}
